package com.agriculture.competition.controller;

import com.agriculture.common.core.utils.poi.ExcelUtil;
import com.agriculture.common.core.web.controller.BaseController;
import com.agriculture.common.core.web.domain.AjaxResult;
import com.agriculture.common.core.web.page.TableDataInfo;
import com.agriculture.common.log.annotation.Log;
import com.agriculture.common.log.enums.BusinessType;
import com.agriculture.common.security.annotation.RequiresPermissions;
import com.agriculture.competition.domain.JaCompetitionInvitation;
import com.agriculture.competition.domain.vo.JaCompetitionInvitationVo;
import com.agriculture.competition.service.IJaCompetitionInvitationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 比赛受邀人Controller
 *
 * @author agriculture
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/invitation")
public class JaCompetitionInvitationController extends BaseController {
    @Autowired
    private IJaCompetitionInvitationService jaCompetitionInvitationService;

    /**
     * 查询比赛受邀人列表
     */
    //@RequiresPermissions("system:invitation:list")
    @GetMapping("/list")
    public TableDataInfo list(JaCompetitionInvitationVo jaCompetitionInvitation) {
        startPage();
        List<JaCompetitionInvitation> list = jaCompetitionInvitationService.selectJaCompetitionInvitationList(jaCompetitionInvitation);
        return getDataTable(list);
    }

    /**
     * 导出比赛受邀人列表
     */
    @RequiresPermissions("system:invitation:export")
    @Log(title = "比赛受邀人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JaCompetitionInvitationVo jaCompetitionInvitation) {
        List<JaCompetitionInvitation> list = jaCompetitionInvitationService.selectJaCompetitionInvitationList(jaCompetitionInvitation);
        ExcelUtil<JaCompetitionInvitation> util = new ExcelUtil<JaCompetitionInvitation>(JaCompetitionInvitation.class);
        util.exportExcel(response, list, "比赛受邀人数据");
    }

    /**
     * 获取比赛受邀人详细信息
     */
    @RequiresPermissions("system:invitation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(jaCompetitionInvitationService.selectJaCompetitionInvitationById(id));
    }

    /**
     * 新增比赛受邀人
     */
    //@RequiresPermissions("system:invitation:add")
    @Log(title = "比赛受邀人", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JaCompetitionInvitation jaCompetitionInvitation) {
        return toAjax(jaCompetitionInvitationService.insertJaCompetitionInvitation(jaCompetitionInvitation));
    }

    /**
     * 修改比赛受邀人
     */
    //@RequiresPermissions("system:invitation:edit")
    @Log(title = "比赛受邀人", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    public AjaxResult edit(@RequestBody JaCompetitionInvitation jaCompetitionInvitation) {
        return toAjax(jaCompetitionInvitationService.updateJaCompetitionInvitation(jaCompetitionInvitation));
    }

    /**
     * 删除比赛受邀人
     */
    // @RequiresPermissions("system:invitation:remove")
    @Log(title = "比赛受邀人", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult remove(@RequestBody Map<String, Object> vo) {
        return toAjax(jaCompetitionInvitationService.deleteJaCompetitionInvitationByUserIds(vo));
    }
}
